﻿using System.Collections.Generic;
namespace GX
{
	public class TrieNode
	{
        char _value;
        bool _isKeyword;
        int _count;
        
        TrieNode _parent;
        Dictionary<char, TrieNode> _children;
        public TrieNode(char value)
        {
            _value = value;
            _children = new Dictionary<char, TrieNode>();
        }
        public char value { get { return _value; } }
        public bool isKeyword { get { return _isKeyword; } }
        public int count { get { return _count; } }
        public TrieNode parent { get { return _parent; } }
        public TrieNode GetChild(char value)
        {
            TrieNode child = null;
            _children.TryGetValue(value,out child);
            return child;
        }
        public void AddKeyword(string text, int index)
        {
            ++_count;
            if (index == text.Length - 1)
            {
                _isKeyword = true;
                return;
            }

            index += 1;

            char key = text[index];
            TrieNode node = GetChild(key);
            if (null == node)
            {
                node = new TrieNode(key);
                _children[key] = node;
                node._parent = this;
            }
            node.AddKeyword(text,index);
        }
	
	}	
}